#{extends 'sidebar.html' /}
#{set 'title'}
Meetings
#{/set}
#{if u.size()==0 && uAdmin.size()==0}
<div><b style="font-size:small;" class="smartBarHeader" >There are no running meetings </b></div>
#{/if}

#{else}
#{list items:u, as:'users'}
<div style="float:left;width:4.5cm;">
<h6>${users.meeting.name}</h6>

<a title="end meeting?" href="javascript: end(${users.meeting.id});"><img src="@{'/public/images/famfam/cancel.png'}"></a><br/>
<div class="formatTime">${users.meeting.startTime}</div>
<div id="amr" class="formatTime">${users.meeting.endTime}</div>
#{list items:users , as:'user'}
<a id="${user.id}_user" href="javascript: select_user(${user.id}, '${user.name}');" class="select">${user.name}</a><br/>
#{/list}
<span id="tzcd_${users.meeting.id}"></span><br/>
<script type="text/javascript" charset="utf-8"> 
// CONFIGURE THE COUNTDOWN SCRIPT HERE
var date=${users.meeting.endTime};
var tz =0;         //  
var lab = 'tzcd_'+${users.meeting.id};    //  The id of the page entry where the timezone countdown is to show

displayTZCountDown(setTZCountDown(date,tz),lab);

function setTZCountDown(date,tz) 
{
	var toDate=new Date(date);
	var fromDate = new Date();
	fromDate.setMinutes(fromDate.getMinutes());
	var diffDate = new Date(0);
	diffDate.setMilliseconds(toDate - fromDate);
	return Math.floor(diffDate.valueOf()/1000);
}
function displayTZCountDown(countdown,tzcd) 
{
	if (countdown < 0)  
	{
		var answer=confirm('Meeting time has ended now ,Do you want to extend for another hour?')
		if (answer) 
		{
			extend(${users.meeting.id});
			
		}
		else
		{
			window.location.reload();
		}	
	}
	else 
	{
		var secs = countdown % 60; 
		if (secs < 10) secs = '0'+secs;
		var countdown1 = (countdown - secs) / 60;
		var mins = countdown1 % 60; 
		if (mins < 10) mins = '0'+mins;
		countdown1 = (countdown1 - mins) / 60;
		var hours = countdown1 % 24;
		var days = (countdown1 - hours) / 24;
		document.getElementById(tzcd).innerHTML = days + " day" + (days == 1 ? '' : 's') + ' : ' +hours+ 'hours : ' +mins+ 'm : '+secs+'s';
		setTimeout('displayTZCountDown('+(countdown-1)+',\''+tzcd+'\');',999);
	}
}
</script>
<div id="myLayer"></div>
</div>
#{/list}

#{list items:uAdmin, as:'users'}
<div style="float:left;width:4.5cm;">
<h6>${users.meeting.name}</h6>

<a class="tiptitize" title="join" href="javascript: join(${users.meeting.id});"><img src="@{'/public/images/famfam/go.png'}"></a><br/>
<div class="formatTime">${users.meeting.startTime}</div>
<div id="amr" class="formatTime">${users.meeting.endTime}</div>
#{if users.size()==0}
No Attendees
#{/if}
#{else}
#{list items:users , as:'user'}
<div id="${user.id}">${user.name}</div>
#{/list}
#{/else}
<br/>
<div id="myLayer"></div>
</div>
<!--Amr Abdelwahab-->
#{/list}
#{/else}	

<script>
	
	
	
	function end(id) {
	var ans=confirm('are you sure you want to end the meeting?');
	if(ans){
	$.post('/Meetings/end', {meetingid:id},function(){
		window.location.reload()
	});
	
	}
	}
	function join(id)
	{
	$.post('/Meetings/joinMeeting', {meetingID:id},function()
	{
		window.location.reload();
	});}
		
		function extend(id) {
		$.post('/Meetings/extend', {meetingid:id}, function(){
		$.bar({message:"Meeting extended!"});
		window.location.reload();
	
			});
	
	
	}
	
		
	
	
	function select_user(id, str) 
 	{
	$('.nostatus').addClass('drag');	
 	 var statusList = ${us};
	 var f_status = false;
	 for(var j=0; j<statusList.length; j++)
     {
     if(statusList[j]==id)
	 {
	 	f_status = true;
	 }
     }
	if(f_status)
	{
		$('.status').css('cursor','move');
		$('.nostatus').css('cursor','move');
		$('.drag').live('mouseover', function(){
		REDIPS.drag.enable_drag(true);		
		});
	}
	else
	{
		$('.status').attr('onmouseover',"");
		$('.status').attr('onhover',"");
		$('.nostatus').attr('onmouseover',"");
		$('.nostatus').attr('onhover',"");
		$('.drag').live('mouseover', function(){
		REDIPS.drag.enable_drag(false);		
		});
		$('.status_'+id).live('mouseover', function(){
		REDIPS.drag.enable_drag(true);		
		});
	}	
	$('.editDES').css('display','none');
	$('.noedit').css('display','none');
	$('.shwtype').css('display','none');		
	$('.hidestype').css('display','none');
	 selectedUser = id;
	 $('#myLayer').html(str+' is editing the Board now '+ '<br/><br/>').effect('highlight',{}, 6000).fadeOut();
	 $('#myLayer').css("color","black");
	 var descList = ${ud};
	 var f_desc = false;
     for(var j=0; j<descList.length; j++)
     {
     if(descList[j]==id)
	 {
	 	f_desc = true;
	 }
     }
	if(f_desc)
	{
	$('.noedit').css('display','none');
	$('.editDES').css('display','inline-block');			
	}
	else
	{
	$('.noedit').css('display','inline-block');
	$('.noedit_'+id).css('display','none');
	$('.editdesc_'+id).css('display','inline-block');	
	}
	
	 		
			
	 var assiList = ${ua};
	 var f_assi = false;
	 
     for(var j=0; j<assiList.length; j++)
    {
     if(assiList[j]==id)
	 {
	 	f_assi = true;
	 }
    }
	if(f_assi)
	{
	$('.showdesc').css('display','none');
	$('.hidesassi').css('display','inline-block');		
	
	}
	else
	{
	$('.hidesassi').css('display','none');
	$('.showdesc').css('display','inline-block');
	}
	
	 
	 var revList = ${ur};
	 var f_rev = false;
	 
     for(var l=0; l<revList.length; l++)
    {
     if(revList[l]==id)
	 {
	 	f_rev = true;
	 }
    }
	if(f_rev)
	{
	$('.showrev').css('display','none');
	$('.hidesrev').css('display','inline-block');		
	
	}
	else
	{
	$('.showrev').css('display','inline-block');
	$('.hidesrev').css('display','none');		
	
	}
	
	 var typeList = ${ut};
	 var f_type = false;
	 
     for(var l=0; l<typeList.length; l++)
    {
     if(typeList[l]==id)
	 {
	 	f_type = true;
	 }
    }
	if(f_type)
	{
	$('.shwtype').css('display','none');		
	$('.hidestype').css('display','inline-block');		
	}
	else
	{
	$('.shwtype').css('display','inline-block');
	$('.shwtype_'+id).css('display','none');		
	$('.shows_'+id).css('display','inline-block');
					
	}
	
	
	}

</script>
